package com.dhcc.ws.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
/**
 * 
* <p>标题: EmergencyClient.java</p>
* <p>业务描述:应急指挥办接口调用前置机客户端</p>
* <p>公司:东华软件股份公司</p>
* <p>版权:dhcc2013</p>
* @author 胡凯
* @date Mar 29, 2019
* @version V1.0
 */
public class WsCallUtil {
	private static Log logger = LogFactory.getLog(WsCallUtil.class);

	static JaxWsDynamicClientFactory dcf = null;
	private static void getWsDynamicClientFactory(){
		if(null==dcf) {
			//为空时，取值
			dcf = JaxWsDynamicClientFactory.newInstance();
		}
	}
	
	public static String callService(String wsUrl,String callMethod,String args){
		logger.info("调用地址："+wsUrl+" \n 请求方法="+callMethod+"("+args+")");
		String returnXml = "";
		try {
			getWsDynamicClientFactory();
			Client client = (Client)dcf.createClient(wsUrl);
			Object[] res = new Object[0];
			if(args!=null) {
				res = client.invoke(callMethod,args);
			}else {
				res = client.invoke(callMethod);
			}
			returnXml = res[0].toString();
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
//		logger.info("returnXml="+returnXml);
		return returnXml;
	}
	
	public static void main(String[] args) {
		String url = "http://192.168.5.60:8090/rarp/ws/arpToThirdWService?wsdl";
		String callMethod = "queryOrgs";
		String arg = "<Request>" + 
				"<HospitalMark></HospitalMark >" + 
				"</Request >";
		String returnXml = callService(url,callMethod,arg);
		System.out.println(returnXml);
	}
}
